- page_title _("CI/CD Settings")
- page_title _("CI/CD")
- @force_desktop_expanded_sidebar = true

- expanded = expanded_by_default?
- general_expanded = @project.errors.empty? ? expanded : true

%section.settings#js-general-pipeline-settings.no-animate{ class: ('expanded' if general_expanded) }
  .settings-header
    %h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only
      = _("General pipelines")
    = render Pajamas::ButtonComponent.new(button_options: { class: 'js-settings-toggle' }) do
      = expanded ? _('Collapse') : _('Expand')
    %p
      = _("Customize your pipeline configuration.")
  .settings-content
    = render 'form'

%section.settings#autodevops-settings.no-animate{ class: ('expanded' if expanded), data: { qa_selector: 'autodevops_settings_content' } }
  .settings-header
    %h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only
      = s_('CICD|Auto DevOps')
    = render Pajamas::ButtonComponent.new(button_options: { class: 'js-settings-toggle' }) do
      = expanded ? _('Collapse') : _('Expand')
    %p
      - auto_devops_url = help_page_path('topics/autodevops/index')
      - quickstart_url = help_page_path('topics/autodevops/cloud_deployments/auto_devops_with_gke')
      - auto_devops_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: auto_devops_url }
      - quickstart_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: quickstart_url }
      = s_('AutoDevOps|%{auto_devops_start}Automate building, testing, and deploying%{auto_devops_end} your applications based on your continuous integration and delivery configuration. %{quickstart_start}How do I get started?%{quickstart_end}').html_safe % { auto_devops_start: auto_devops_start, auto_devops_end: '</a>'.html_safe, quickstart_start: quickstart_start, quickstart_end: '</a>'.html_safe }
  .settings-content
    = render 'autodevops_form', auto_devops_enabled: @project.auto_devops_enabled?

= render_if_exists 'projects/settings/ci_cd/protected_environments', expanded: expanded

- expand_runners = expanded || params[:expand_runners]
%section.settings.no-animate#js-runners-settings{ class: ('expanded' if expand_runners), data: { qa_selector: 'runners_settings_content' } }
  .settings-header
    %h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only
      = _("Runners")
    = render Pajamas::ButtonComponent.new(button_options: { class: 'js-settings-toggle' }) do
      = expand_runners ? _('Collapse') : _('Expand')
    %p
      = _("Runners are processes that pick up and execute CI/CD jobs for GitLab.")
      = link_to s_('What is GitLab Runner?'), 'https://docs.gitlab.com/runner/', target: '_blank', rel: 'noopener noreferrer'
  .settings-content
    - if Feature.enabled?(:project_runners_vue_ui, @project)
      #js-project-runners{ data: { project_full_path: @project.full_path } }
    - else
      = render 'projects/runners/settings'

- if Gitlab::CurrentSettings.current_application_settings.keep_latest_artifact?
  %section.settings.no-animate#js-artifacts-settings{ class: ('expanded' if expanded) }
    .settings-header
      %h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only
        = _("Artifacts")
      = render Pajamas::ButtonComponent.new(button_options: { class: 'js-settings-toggle' }) do
        = expanded ? _('Collapse') : _('Expand')
      %p
        = _("A job artifact is an archive of files and directories saved by a job when it finishes.")
    .settings-content
      #js-artifacts-settings-app{ data: { full_path: @project.full_path, help_page_path: help_page_path('ci/jobs/job_artifacts', anchor: 'keep-artifacts-from-most-recent-successful-jobs') } }

%section.settings.no-animate#js-cicd-variables-settings{ class: ('expanded' if expanded), data: { qa_selector: 'variables_settings_content' } }
  .settings-header
    = render 'ci/variables/header', expanded: expanded
  .settings-content
    = render 'ci/variables/index', save_endpoint: project_variables_path(@project)

%section.settings.no-animate#js-pipeline-triggers{ class: ('expanded' if expanded) }
  .settings-header
    %h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only
      = _("Pipeline trigger tokens")
    = render Pajamas::ButtonComponent.new(button_options: { class: 'js-settings-toggle' }) do
      = expanded ? _('Collapse') : _('Expand')
    %p.gl-text-secondary.gl-mb-0
      = _("Trigger a pipeline for a branch or tag by generating a trigger token and using it with an API call. The token impersonates a user's project access and permissions.")
      = link_to _('Learn more.'), help_page_path('ci/triggers/index'), target: '_blank', rel: 'noopener noreferrer'
  .settings-content
    = render 'projects/triggers/index'

= render_if_exists 'projects/settings/ci_cd/auto_rollback', expanded: expanded

- if can?(current_user, :create_freeze_period, @project)
  %section.settings.no-animate#js-deploy-freeze-settings{ class: ('expanded' if expanded) }
    .settings-header
      %h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only
        = _("Deploy freezes")
      = render Pajamas::ButtonComponent.new(button_options: { class: 'js-settings-toggle' }) do
        = expanded ? _('Collapse') : _('Expand')
      %p
        - freeze_period_docs = help_page_path('user/project/releases/index', anchor: 'prevent-unintentional-releases-by-setting-a-deploy-freeze')
        - freeze_period_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: freeze_period_docs }
        = html_escape(s_('DeployFreeze|Add a freeze period to prevent unintended releases during a period of time for a given environment. You must update the deployment jobs in %{filename} according to the deploy freezes added here. %{freeze_period_link_start}Learn more.%{freeze_period_link_end}')) % { freeze_period_link_start: freeze_period_link_start, freeze_period_link_end: '</a>'.html_safe, filename: tag.code('.gitlab-ci.yml') }

        - cron_syntax_url = 'https://crontab.guru/'
        - cron_syntax_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: cron_syntax_url }
        = s_('DeployFreeze|Specify deploy freezes using %{cron_syntax_link_start}cron syntax%{cron_syntax_link_end}.').html_safe % { cron_syntax_link_start: cron_syntax_link_start, cron_syntax_link_end: "</a>".html_safe }

    .settings-content
      = render 'ci/deploy_freeze/index'

%section.settings.no-animate#js-token-access{ class: ('expanded' if expanded) }
  .settings-header
    %h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only
      = _("Token Access")
    = render Pajamas::ButtonComponent.new(button_options: { class: 'js-settings-toggle' }) do
      = expanded ? _('Collapse') : _('Expand')
    %p.gl-text-secondary
      = _("Control how the CI_JOB_TOKEN CI/CD variable is used for API access between projects.")
  .settings-content
    = render 'ci/token_access/index'

- if show_secure_files_setting(@project, current_user)
  %section.settings.no-animate#js-secure-files{ class: ('expanded' if expanded) }
    .settings-header
      %h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only
        = _("Secure Files")
      = render Pajamas::ButtonComponent.new(button_options: { class: 'js-settings-toggle' }) do
        = expanded ? _('Collapse') : _('Expand')
      %p.gl-text-secondary.gl-mb-0
        = _("Use Secure Files to store files used by your pipelines such as Android keystores, or Apple provisioning profiles and signing certificates.")
        = link_to _('Learn more'), help_page_path('ci/secure_files/index'), target: '_blank', rel: 'noopener noreferrer'
    .settings-content
      #js-ci-secure-files{ data: { project_id: @project.id, admin: can?(current_user, :admin_secure_files, @project).to_s, file_size_limit: Ci::SecureFile::FILE_SIZE_LIMIT.to_mb } }
